package com.boot2.core.exception;

import com.boot2.core.utils.ResultBuilder;
import lombok.Data;
import lombok.extern.apachecommons.CommonsLog;

import java.util.Map;

/**
 * @author zhangweilin
 * @date 2018/9/10 18:03
 * @description: 按错误编码返回的异常
 */
@CommonsLog
@Data
public class ErrorCodeException extends RuntimeException {
    private static final long serialVersionUID = -8500433014836195629L;

    private static Map<String, String> _errorMap = ResultBuilder.getErrorMap();
    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 错误消息
     */
    private String errorMessage;

    public ErrorCodeException(String errorCode) {
        super("【errorCode】:" + errorCode + ",【errorMessage】:" +  _errorMap.get(errorCode));
//        log.error("【errorCode】:" + errorCode + ",【errorMessage】:" +  _errorMap.get(errorCode));
        this.errorCode = errorCode;
        this.errorMessage =  _errorMap.get(errorCode);
    }

    public ErrorCodeException(String errorCode, String errorMessage) {
        super("【errorCode】:" + errorCode + ",【errorMessage】:" + errorMessage);
//        log.error("【errorCode】:" + errorCode + ",【errorMessage】:" + errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public ErrorCodeException(String errorCode, String errorMessage, Throwable cause) {
        super("【errorCode】:" + errorCode + ",【errorMessage】:" + errorMessage, cause);
//        log.error("【errorCode】:" + errorCode + ",【errorMessage】:" + errorMessage,cause);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

}
